package com.tencent.iov.cowin.befsale.clue.service.cus.impl;

import com.github.pagehelper.Page;
import com.tencent.iov.cowin.befsale.clue.domain.cus.po.OemCustomerTagRel;
import com.tencent.iov.cowin.befsale.clue.repository.cus.OemCustomerTagRelManager;
import com.tencent.iov.cowin.befsale.clue.service.cus.OemCustomerTagRelService;
import com.software.boot.common.model.dao.PageRequest;
import com.software.boot.common.model.dao.PageResponse;
import com.software.boot.common.util.BeanUtil;
import com.software.boot.common.util.EmptyUtils;
import com.software.boot.common.util.ValidateUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Describe: 总部客户标签关联表_Service实现层
 * @author: xiamu
 * @created: 2021-12-21 18:37:34
 * @version: 1.0
 */
@Service
public class OemCustomerTagRelServiceImpl implements OemCustomerTagRelService {

    @Autowired
    private OemCustomerTagRelManager oemCustomerTagRelManager;

    /**
     * 通过ID获取详细信息
     *
     * @param: request
     * @return: OemCustomerTagRel对象
     */
    @Override
    public OemCustomerTagRel getDetailById(Long id) {
        /** 1 验证请求参数 */
        ValidateUtils.checkObjNull(id, "请求参数不能为空");
        ValidateUtils.checkIntNotNullAndGTZero(id.intValue(), "ID不能为空或小于0");
        /** 2 处理业务 */
        OemCustomerTagRel oemCustomerTagRel = oemCustomerTagRelManager.getDetailById(id);
        if (EmptyUtils.isNotEmpty(oemCustomerTagRel)) {
            return BeanUtil.copy(oemCustomerTagRel, OemCustomerTagRel.class);
        }
        /** 3 返回结果 */
        return null;
    }

    /**
     * 单条数据插入OemCustomerTagRel
     *
     * @param request
     * @return 插入的条数
     */
    @Override
    public int insert(OemCustomerTagRel request) {
        /** 1 验证请求参数 */
        /** 2 处理业务 */
        int count = oemCustomerTagRelManager.insert(request);
        /** 3 封装返回值 */
        return count;
    }

    /**
     * 批量插入OemCustomerTagRel
     *
     * @param requests
     * @return 批量插入的条数
     */
    @Override
    public int insertBatch(List<OemCustomerTagRel> requests) {
        /** 1 验证请求参数 */
        /** 2 处理业务 */
        int count = oemCustomerTagRelManager.insertBatch(requests);
        /** 3 封装返回值 */
        return count;
    }


    /**
     * 单条OemCustomerTagRel更新
     *
     * @param request
     * @return 更新的条数
     */
    @Override
    public int update(OemCustomerTagRel request) {

        /** 1 验证请求参数 */
        /** 2 处理业务 */
        int count = oemCustomerTagRelManager.update(request);
        /** 3 返回对象 */
        return count;
    }

    /**
     * 通过ID删除数据
     *
     * @param request
     * @return 删除的条数
     */
    @Override
    public int delete(OemCustomerTagRel request) {
        Long id = request.getId();
        /** 1 验证请求参数 */
        ValidateUtils.checkObjNull(id, "请求参数不能为空");
        ValidateUtils.checkIntNotNullAndGTZero(id.intValue(), "ID不能为空或小于0");
        /** 2 处理业务 */
        OemCustomerTagRel oemCustomerTagRel = new OemCustomerTagRel();
        oemCustomerTagRel.setId(id);
//		oemCustomerTagRel.setDelete(DeleteEnum.DETELED.getCode());
        int count = oemCustomerTagRelManager.update(oemCustomerTagRel);
        /** 3 返回对象 */
        return count;
    }

    /**
     * 根据条件查询对象对象list列表
     *
     * @param request
     * @return 查询结果
     */
    @Override
    public List<OemCustomerTagRel> getListByParam(OemCustomerTagRel request) {
        /** 1 验证请求参数 */
        //可以设置排序
        /** 2 处理业务 */
        List<OemCustomerTagRel> queryList = oemCustomerTagRelManager.getListByParam(request);
        /** 3 返回结果 */
        if (CollectionUtils.isNotEmpty(queryList)) {
            return BeanUtil.copyByList(queryList, OemCustomerTagRel.class);
        }
        return new ArrayList<>();
    }

    /**
     * 根据条件查询对象list记录
     *
     * @param request
     * @return 分页对象
     */
    @Override
    public PageResponse<OemCustomerTagRel> getPageByParam(PageRequest<OemCustomerTagRel> request) {
        /** 1 验证请求参数 */
        ValidateUtils.checkObjNull(request, "请求参数不能为空");
        //可以设置排序 query.orderByCreatedTime(true);
        /** 2 处理业务 */
        RowBounds rowBounds = new RowBounds(request.getPageNum(), request.getPageSize());
        Page<OemCustomerTagRel> queryPageList = oemCustomerTagRelManager.getPageByParam(request.getParamData(), rowBounds);
        PageResponse<OemCustomerTagRel> pageResponse = new PageResponse<>();
        pageResponse.converPageResponse(pageResponse, queryPageList, request);
        pageResponse.setDataList(BeanUtil.copyByList(queryPageList.getResult(), OemCustomerTagRel.class));
        /** 3 返回结果 */
        return pageResponse;
    }

    /**
     * 根据条件查询单个对象
     *
     * @param request
     * @return
     */
    @Override
    public OemCustomerTagRel getOneByParam(OemCustomerTagRel request) {
        return oemCustomerTagRelManager.getOneByParam(request);
    }
}
